package com.source.barcodeMachineRepairAndScrap.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.source.barcodeMachineRepairAndScrap.entity.BarcodeMachineRepair;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.source.barcodeMachineRepairAndScrap.vo.BarcodeMachineRepairVO;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author IceBerg777
 * @since 2021-03-07
 */
public interface BarcodeMachineRepairMapper extends BaseMapper<BarcodeMachineRepair> {

    String SELECT = "SELECT bmr.* , su.`name` repairName \n" +
            "FROM barcode_machine_repair bmr , sys_user su \n" +
            "WHERE bmr.repairPerson = su.userId AND bmr.isDelete = 0 \n" ;

    @Select(value = "SELECT bmr.* , su.`name` repairName \n" +
            "FROM barcode_machine_repair bmr , sys_user su \n" +
            "WHERE bmr.repairPerson = su.userId AND bmr.isDelete = 0\n" +
            "ORDER BY bmr.repairId DESC ")
    IPage<BarcodeMachineRepairVO> findAllRepairOnPagination(Page<BarcodeMachineRepairVO> page);

    @Select(value = "SELECT bmr.* , su.`name` repairName \n" +
            "FROM barcode_machine_repair bmr , sys_user su \n" +
            "WHERE bmr.repairPerson = su.userId AND bmr.isDelete = 0\n" +
            "AND CONCAT_WS(',',repairId, barcodeMachineNumber, bmr.createDate, repairAddr, repairDate, su.`name`, msg, bmr.`status`) LIKE #{keyWord} \n" +
            "ORDER BY bmr.repairId DESC  ")
    IPage<BarcodeMachineRepairVO> findByMultiKeysOnPagination(Page<BarcodeMachineRepairVO> page, String keyWord);

    @Select(value = "SELECT bmr.* , su.`name` repairName \n" +
            "FROM barcode_machine_repair bmr , sys_user su \n" +
            "WHERE bmr.repairPerson = su.userId AND bmr.isDelete = 0 AND bmr.repairId = #{id}\n" +
            "ORDER BY bmr.repairId DESC ")
    BarcodeMachineRepairVO findById(String id);

    @Select(SELECT + "ORDER BY bmr.repairId DESC ")
    List<BarcodeMachineRepairVO> findAllRepair();
}
